package routinecontroller

import (
	//"agent-list---web-development/list/common"
	"agent-list---web-development/list/common"
	"agent-list---web-development/list/model"
	"agent-list---web-development/list/response"
	"net/http"

	"github.com/gin-gonic/gin"
)

func ShowRoutine(c *gin.Context) {
	//获取参数
	DB := common.DB
	account := c.Query("account")
	//数据验证
	if len(account) != 7 {
		response.Response(c, http.StatusUnprocessableEntity, 422, gin.H{"account": account}, "用户账号格式错误！")
		return
	}
	var routine []model.Routine
	DB.Where("useraccount=?", account).Find(&routine)
	if len(routine) == 0 {
		response.Response(c, http.StatusNotFound, 404, nil, "未找到相关记录!")
		return
	}
	titles := make([]string, len(routine))
	for i, value := range routine {
		titles[i] = value.Title
	}
	len := len(titles)
	response.Success(c, gin.H{"titles": titles, "len": len}, "获取成功!")
}
